package cn.kgc.shiro;

import cn.kgc.shiro.utils.SaltUtil;
import org.apache.shiro.crypto.hash.Md5Hash;

/**
 * @author 课工场
 * @date 2023/11/21
 * @description  shiro的加密操作
 */
public class ShiroMD5 {

    public static void main(String[] args) {

        String  password = "123456";    //  e10adc3949ba59abbe56e057f20f883e
        Md5Hash md5Hash = new Md5Hash(password);
        String hex = md5Hash.toHex();
        System.out.println("hex = " + hex);

        // 为了提升密码的强度  加密之前  做加盐处理  salt  hello 秘钥
        md5Hash = new Md5Hash(password,"hello");
         hex = md5Hash.toHex();
        System.out.println("hex = " + hex);  //eeb9bad681184779aa6570e402d6ef6c

        // 随机盐   tom   123456  hello    jack   123456  hello2    username  password  salt
        String randomSalt = SaltUtil.getRandomSalt(8);

        md5Hash = new Md5Hash(password,randomSalt);
        hex = md5Hash.toHex();
        System.out.println("randomSalt = " + randomSalt);
        System.out.println("hex = " + hex);


        String randomSalt1 = SaltUtil.getRandomSalt(8);
        md5Hash =   new  Md5Hash(password,randomSalt1);
        hex = md5Hash.toHex();
        System.out.println("randomSalt1 = " + randomSalt1);
        System.out.println("hex = " + hex);  //  TPMb.h64    0bb671ebf22565395c28c9ef361d45be

        md5Hash = new Md5Hash(password,randomSalt1,10);
        String hex1 = md5Hash.toHex();
        System.out.println("hex1 = " + hex1);   // de925b88805731d32dc7ff541684c5a8

    }
}
